<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <ul id="ul">
    <li>lhf</li>
    <li>18</li>
    <li>专注前端</li>
  </ul>
</body>
<script>
  // var list = document.getElementsByTagName('li')
  // for(var ele of list){
  //   ele.onclick=(e)=>{
  //     console.log(e.target.innerHTML)
  //   }
  // }
  /**采用事件委托能减少事件绑定。提高性能*/
  var ul = document.getElementById('ul')
  ul.addEventListener('click',(e)=>{
    if(e.target.nodeName.toLowerCase()==='li'){
      console.log(e.target.innerHTML)
    }
  })
</script>
</html>